<?php
/**
 * Created by PhpStorm.
 * User: fangwei
 * Date: 2019-09-12
 * Time: 22:26
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\ISupplier;
use App\Http\Requests\Admin\SupplierInputDTO;
use App\Util\LayUiVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class SupplierController extends Controller
{
    protected $supplierService;
    public function __construct(ISupplier $supplierService)
    {
        $this->supplierService = $supplierService;
    }

    public function show($id) {
        $dao = $this->supplierService->byId($id);
        return response()->json(new LayUiVo(['data'=>$dao,'message'=>Lang::get('response.message')]));
    }

    public function page(Request $request) {
        $search = [];
        $data = $this->supplierService->lists($search,$request->get('page',1),$request->get('limit',10));
        return response()->json(new LayUiVo(['data'=>$data,'message'=>Lang::get('response.message')]));
    }

    public function store(SupplierInputDTO $inputDTO) {
        $this->supplierService->store($inputDTO);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.message')]));
    }

    public function update(SupplierInputDTO $inputDTO,$id){
        $this->supplierService->update($inputDTO,$id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.message')]));
    }

    public function delete($id) {
        $this->supplierService->delete($id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.message')]));
    }
}